package com.huawei.appmarket.service.activitydispatcher;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import androidx.annotation.Nullable;
import com.huawei.appgallery.jsonkit.api.JsonBean;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import o.Logger;
import o.fjb;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class OpenGateway {
    private static Map<String, Class<? extends e>> ˋ = new HashMap();
    private static final List<String> ॱ = new ArrayList();

    public static class Param extends JsonBean {
        public static final String TYPE_BOOLEAN = "boolean";
        public static final String TYPE_FLOAT = "float";
        public static final String TYPE_INT = "int";
        public static final String TYPE_LONG = "long";
        public static final String TYPE_STR = "String";
        private String iv_;
        private String name_;
        private String type_;
        private String value_;

        public String ˋ() {
            return this.name_;
        }

        public void ˎ(String str) {
            this.name_ = str;
        }

        public String ˎ() {
            return this.type_;
        }

        public void ˋ(String str) {
            this.type_ = str;
        }

        public String ˏ() {
            return this.value_;
        }

        public void ˏ(String str) {
            this.value_ = str;
        }

        public String ॱ() {
            return this.iv_;
        }
    }

    public static abstract class d {
        public abstract boolean ˋ(List<Param> list);

        public abstract fjb ˏ(List<Param> list);

        public List<Param> ॱ(List<Param> list) {
            return list;
        }

        public void ˋ(Intent intent) {
        }
    }

    public static abstract class e {
        public abstract c ˋ(String str, List<Param> list, boolean z);

        public static boolean ˎ(List<Param> list, Bundle bundle) {
            for (Param ˎ : list) {
                if (!ˎ(ˎ, bundle)) {
                    return false;
                }
            }
            return true;
        }

        private static boolean ˎ(Param param, Bundle bundle) {
            if (param == null || TextUtils.isEmpty(param.ˋ()) || TextUtils.isEmpty(param.ˎ())) {
                return false;
            }
            try {
                if (Param.TYPE_STR.equals(param.ˎ())) {
                    bundle.putString(param.ˋ(), param.ˏ());
                } else if (Param.TYPE_INT.equals(param.ˎ())) {
                    bundle.putInt(param.ˋ(), Integer.parseInt(param.ˏ()));
                } else if (Param.TYPE_FLOAT.equals(param.ˎ())) {
                    bundle.putFloat(param.ˋ(), Float.parseFloat(param.ˏ()));
                } else if (Param.TYPE_LONG.equals(param.ˎ())) {
                    bundle.putLong(param.ˋ(), Long.parseLong(param.ˏ()));
                } else if (!Param.TYPE_BOOLEAN.equals(param.ˎ())) {
                    return false;
                } else {
                    bundle.putBoolean(param.ˋ(), Boolean.parseBoolean(param.ˏ()));
                }
                return true;
            } catch (Throwable e) {
                Logger.ˋ("OpenGateway", "setParam exception", e);
                return false;
            }
        }

        protected static boolean ˊ(Param param, Map<String, Object> map) {
            if (param == null || TextUtils.isEmpty(param.ˋ()) || TextUtils.isEmpty(param.ˎ())) {
                return false;
            }
            try {
                if (Param.TYPE_STR.equals(param.ˎ())) {
                    map.put(param.ˋ(), param.ˏ());
                } else if (Param.TYPE_INT.equals(param.ˎ())) {
                    map.put(param.ˋ(), Integer.valueOf(Integer.parseInt(param.ˏ())));
                } else if (Param.TYPE_FLOAT.equals(param.ˎ())) {
                    map.put(param.ˋ(), Float.valueOf(Float.parseFloat(param.ˏ())));
                } else if (Param.TYPE_LONG.equals(param.ˎ())) {
                    map.put(param.ˋ(), Long.valueOf(Long.parseLong(param.ˏ())));
                } else if (!Param.TYPE_BOOLEAN.equals(param.ˎ())) {
                    return false;
                } else {
                    map.put(param.ˋ(), Boolean.valueOf(Boolean.parseBoolean(param.ˏ())));
                }
                return true;
            } catch (Throwable e) {
                Logger.ˋ("OpenGateway", "setParam exception", e);
                return false;
            }
        }
    }

    static {
        ˋ("com.huawei.appgallery.packagemanager.impl.install.process.PackageInstallerActivity");
        ˋ("com.huawei.appgallery.packagemanager.impl.install.process.PackageUninstallerActivity");
    }

    public static void ˋ(String str) {
        ॱ.add(str);
    }

    public static void ˏ(String str, Class<? extends e> cls) {
        ˋ.put(str, cls);
    }

    private static Class<? extends e> ˏ(String str) {
        return (Class) ˋ.get(str);
    }

    public static c ˎ(String str, JSONArray jSONArray, boolean z) {
        return ˊ(str, ˏ(jSONArray), z);
    }

    @Nullable
    private static List<Param> ˏ(JSONArray jSONArray) {
        if (jSONArray == null || jSONArray.length() <= 0) {
            return null;
        }
        List<Param> arrayList = new ArrayList();
        for (int i = 0; i < jSONArray.length(); i++) {
            try {
                JSONObject jSONObject = jSONArray.getJSONObject(i);
                Param param = new Param();
                param.fromJson(jSONObject);
                arrayList.add(param);
            } catch (JSONException e) {
                Logger.e("OpenGateway", "can not get JSONObject JSONException");
            } catch (InstantiationException e2) {
                Logger.e("OpenGateway", "can not get JSONObject InstantiationException");
            } catch (ClassNotFoundException e3) {
                Logger.e("OpenGateway", "can not get JSONObject ClassNotFoundException");
            } catch (IllegalAccessException e4) {
                Logger.e("OpenGateway", "can not get JSONObject IllegalAccessException");
            }
        }
        return arrayList;
    }

    public static c ˊ(String str, List<Param> list, boolean z) {
        if (TextUtils.isEmpty(str)) {
            Logger.e("OpenGateway", "can not find activityName");
            return null;
        }
        int indexOf = str.indexOf(124);
        if (indexOf != -1) {
            Class ˏ = ˏ(str.substring(0, indexOf));
            if (ˏ != null) {
                String substring;
                String str2 = "";
                if (str.length() >= indexOf + 1) {
                    substring = str.substring(indexOf + 1);
                } else {
                    substring = str2;
                }
                try {
                    return ((e) ˏ.newInstance()).ˋ(substring, list, z);
                } catch (Throwable e) {
                    Logger.ˋ("OpenGateway", "can not constructor.", e);
                } catch (Throwable e2) {
                    Logger.ˋ("OpenGateway", "can not constructor.", e2);
                }
            }
            return null;
        }
        Logger.e("OpenGateway", "can not find activityName scheme.");
        return null;
    }
}
